﻿@{
    ViewBag.Title = "Lugar";
    ViewBag.slide = "false";
    ViewBag.user = "private";
    ViewBag.perfil = Session["Codigodeperfil"];
}
@section menuLateral{
    <p>
        <br />
        <br />
    </p>
    <ul>
        <li>@Html.ActionLink("Proyecto", "Index", "Proyecto")</li>
        <li>@Html.ActionLink("Tipos de Lugar", "Index", "TipodeLugar")</li>
        <li>@Html.ActionLink("Lugar", "Index", "Lugar")</li>
        <li>@Html.ActionLink("Unidades de Medida", "Index", "UnidaddeMedida")</li>
        <li>@Html.ActionLink("Variable", "Index", "Variable")</li>
        <li>@Html.ActionLink("Rango de Cualidad", "Index", "RangodeCualidad")</li>
        <li>@Html.ActionLink("Equipo de Medicion", "Index", "EquipodeMedicion")</li>
        <li>@Html.ActionLink("Detalle de Equipo", "Index", "DetalledeEquipo")</li>
        <li>@Html.ActionLink("Tipos de Muestra", "Index", "TipodeMuestra")</li>
        <li>@Html.ActionLink("Muestra", "Index", "Muestra")</li>
    </ul>
}
@section equipoMedicion {
    @using (Html.BeginForm("Insertar", "Lugar", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
    
        <p>
            <br />
        </p>
        <fieldset>
            <br />
            <p>@Html.ActionLink("Regresar", "Index")</p>
            <div id="result">
                @if (ViewData.Model.GetType() == typeof(string))
                {
                    <p>@ViewData.Model</p>
                }
                else
                {
                    <p>
                        <b>Desplace el marcador para obtener la latitud y longitud del lugar.</b></p>
                    <div id="mostrarmape" style="width:  565px; height: 300px">
                    </div>
                    <table id="tabla">
                        <thead>
                            <tr>
                                <th colspan="3">
                                    <div align="center">
                                        REGISTRO DE LUGAR</div>
                                </th>
                            </tr>
                        </thead>
                        <tfoot>
                            <tr>
                                <td colspan="3">
                                    <div align="center">
                                        Registro de informacion de lugar</div>
                                </td>
                            </tr>
                        </tfoot>
                        <tbody>
                            <tr>
                                <td class="color7">
                                    <label for="identificador">
                                        Codigo:</label>
                                </td>
                                <td>@Html.TextBox("Identificador", null, new { placeholder = " Ingrese Numeros", autofocus = "autofocus", maxlength = "9", onkeyUp = "return ValNumero(this);" })@Html.ValidationMessage("Identificador", "*")
                                </td>
                            </tr>
                            <tr>
                                <td class="color7">
                                    <label for="nombre">
                                        Nombre:</label>
                                </td>
                                <td>@Html.TextBox("Nombre", null, new { placeholder = "Ingrese Texto", maxlength = "50", onkeypress = "return soloLetras(event)" })
                                </td>
                            </tr>
                            <tr>
                                <td class="color7">
                                    <label for="latitud">
                                        Latitud:</label>
                                </td>
                                <td>@Html.TextBox("Gradoslati", null, new { maxlength = "2", style = "width:30px", onkeyUp = "return ValNumero(this);" })
                                    °&nbsp;
                                    @Html.TextBox("Minutoslati", null, new { maxlength = "2", style = "width:30px", onkeyUp = "return ValNumero(this);" })
                                    '&nbsp;
                                    @Html.TextBox("Segundoslati", null, new { maxlength = "2", style = "width:30px", onkeyUp = "return ValNumero(this);" })
                                    ,&nbsp;
                                    @Html.TextBox("Decimaslati", null, new { maxlength = "2", style = "width:30px", onkeyUp = "return ValNumero(this);" })
                                    ''&nbsp;
                                    <select id="direccionlati" name="direccionlati" >
                                        <option value="0">---Direccion---</option>
                                        <option value="+">Norte</option>
                                        <option value="-">Sur</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td class="color7">
                                    <label for="longitud">
                                        Longitud:</label>
                                </td>
                                <td>@Html.TextBox("Gradoslongi", null, new { maxlength = "3", style = "width:30px", onkeyUp = "return ValNumero(this);" })
                                    °&nbsp;
                                    @Html.TextBox("Minutoslongi", null, new { maxlength = "2", style = "width:30px", onkeyUp = "return ValNumero(this);" })
                                    '&nbsp;
                                    @Html.TextBox("Segundoslongi", null, new { maxlength = "2", style = "width:30px", onkeyUp = "return ValNumero(this);" })
                                    ,&nbsp;
                                    @Html.TextBox("Decimaslongi", null, new { maxlength = "2", style = "width:30px", onkeyUp = "return ValNumero(this);" })
                                    ''&nbsp;
                                    <select id="direccionlongi" name="direccionlongi">
                                        <option value="0">---Direccion---</option>
                                        <option value="+">Este</option>
                                        <option value="-">Oeste</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td class="color7">
                                    <label for="descripcion">
                                        Descripcion:</label>
                                </td>
                                <td>
                                    @Html.TextArea("Descripcion", null, 3, 38, new { maxlength = "100" })
                                </td>
                            </tr>
                            <tr>
                                <td class="color7">
                                    <label for="tipo">
                                        Tipo De Lugar:</label>
                                </td>
                                <td>
                                    <select id="Idtipodelugar" name="Idtipodelugar">
                                        <option value="0">---seleccione---</option>
                                        @foreach (var tip in ViewData.Model.tiposdelugar)
                                        {

                                            <option value="@tip.Identificador">@tip.Nombre</option>

                                        }
                                    </select>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <div align="center">
                        <input type="submit" value="Guardar" /></div>
                    <br />
                    <div align="center">
                        @Html.ValidationMessage("Identificador")
                        <br />
                        @Html.ValidationMessage("Nombre")
                        <br />
                        @Html.ValidationMessage("Latitud")
                        <br />
                        @Html.ValidationMessage("Longitud")
                        <br />
                        @Html.ValidationMessage("Segundos")
                        <br />
                        @Html.ValidationMessage("Direccion")
                        <br />
                        @Html.ValidationMessage("Foto")
                        <br />
                        @Html.ValidationMessage("Descripcion")
                        <br />
                        @Html.ValidationMessage("Idtipodelugar")
                    </div>
                    <br />
                    <div align="center">
                        @Html.ValidationSummary(true, "Error en el  registro de Lugar.Verifique si los campos son correctos")
                    </div>
                }
            </div>
        </fieldset>
    }
}
@section javascript {
<script type="text/javascript">
    $(document).ready(function () {

   var mapa;

    mapa = new google.maps.Map(document.getElementById("mostrarmape"),
    {
        zoom: 11, center: new google.maps.LatLng(1.857222, -76.039474),
        region: "co",
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });
        
      marker = new google.maps.Marker({
                map: mapa,
                position: new google.maps.LatLng(1.857222, -76.039474),
                draggable: true
            });
              function recibircoordenadas(marker) {
            var markerLatLng = marker.getPosition();
            var latitude = markerLatLng.lat().toString();
            var longitude = markerLatLng.lng().toString();
            var iddegreelat = "#Gradoslati";
            var idminuteslat = "#Minutoslati";
            var idsecondslat = "#Segundoslati";
            var iddecimeslat = "#Decimaslati";
            var iddirectionlat = "direccionlati";
            var iddegreelng = "#Gradoslongi";
            var idminuteslng = "#Minutoslongi";
            var idsecondslng = "#Segundoslongi";
            var iddecimeslng = "#Decimaslongi";
            var iddirectionlng = "direccionlongi";
            DDtoDMS(latitude, iddegreelat, idminuteslat, idsecondslat, iddecimeslat, iddirectionlat);
            DDtoDMS(longitude, iddegreelng, idminuteslng, idsecondslng, iddecimeslng, iddirectionlng);

        }

        function DDtoDMS(coordinates, iddegree, idminutes, idseconds, iddecimes, iddirection) {
            var values = coordinates.split('.');
            var degree = values[0];
            var decimals = values[1].substring(0, 6);
            var temporal = "0." + decimals;
            temporal = temporal * 3600;
            var minutes = Math.floor(temporal / 60);
            var seconds = temporal - (minutes * 60);
            var secondstemporal = seconds.toString().split('.');
            var decimes = secondstemporal[1].substring(0, 2);
            if (degree < 0) {
                degree = degree * -1;
                $(iddegree).val(degree);
                document.getElementById(iddirection).options[2].selected = true;
            }
            else {
                $(iddegree).val(degree);
                document.getElementById(iddirection).options[1].selected = true;
            }
            $(idminutes).val(minutes);
            $(idseconds).val(secondstemporal[0]);
            $(iddecimes).val(decimes);
        }
        google.maps.event.addListener(marker, 'mouseup', function () {
            recibircoordenadas(marker);

        });

    });
</script>

}